package day09.KeJian;

import java.util.Comparator;
import java.util.TreeSet;

public class MyTreeSet4 {
    public static void main(String[] args) {
        TreeSet<Teacher> tr = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int result = o1.getAge() - o2.getAge();
                result = result == 0?o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });
        Teacher  t1 = new Teacher("zhangsan",21);
        Teacher  t2 = new Teacher("lisi",22);
        Teacher  t3 = new Teacher("wangwu",23);
        Teacher  t4 = new Teacher("zhaoliu",24);
        tr.add(t1);
        tr.add(t2);
        tr.add(t3);
        tr.add(t4);
        for (Teacher te : tr) {
            System.out.println(te);

        }
    }
}
